/**
 * Created by lx on 2017/9/25.
 */
angular.module('module.table.operation', [
        'service.tablenum'
    ])
    .config(['$stateProvider', function ($stateProvider) {
        $stateProvider
            .state('tablenum', {
                url: '/operation',
                resolve: {
                    shopTableList: ['$q', 'TableNumService', '$state', '$localStorage', function ($q, TableNumService, $state, $localStorage) {
                        if (!$localStorage[environmental + "shopid"]) {
                            $localStorage.$reset();
                            $state.go('login');
                        }
                        var shopid = $localStorage[environmental + "shopid"];
                        var deferred = $q.defer();
                        TableNumService.getTableNumByShopId(shopid, function (success) {
                            deferred.resolve(success);
                        }, function (error) {
                            deferred.resolve("undefined");
                        });
                        return deferred.promise;
                    }]
                },
                templateUrl: table_view_url + 'operation/administration.html',
                controller: 'TableNumController',
                controllerAs: 'vm',
            })
            .state('tabledetail', {
                url: '/tabledetail/:tableid',
                templateUrl: table_view_url + 'operation/detail.html',
                controller: 'TableNumDetailController',
                controllerAs: 'vm',
            })
            .state('scanning', {
                url: '/scanning/:tableid?scan',
                resolve: {
                    scan: ['$stateParams', function ($stateParams) {
                        if (!$stateParams.scan && ismobile(0) == 0) {
                            var url = window.location.href.replace("/tabledetail", "/scanning");
                            url += "?scan=true";
                            window.location.href = url;
                        }
                        return null;
                    }]
                },
                templateUrl: table_view_url + 'operation/scanning.html',
                controller: 'TableNumScanningController',
                controllerAs: 'vm',
            })
            .state('inputsn', {
                url: '/inputsn/:tableid',
                templateUrl: table_view_url + 'operation/inputsn.html',
                controller: 'TableNumInputSnController',
                controllerAs: 'vm',
            })
            .state('mealcode', {
                url: '/mealcode/:tableid',
                templateUrl: table_view_url + 'operation/mealcode.html',
                controller: 'TableNumMealCodeController',
                controllerAs: 'vm',
            })
    }])